package com.ea.admin.controller.sse;

import com.ea.admin.service.SseService;
import com.ea.admin.utils.NowUserGetter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import javax.annotation.Resource;

@Controller
@RequestMapping("/sse")
public class IndexController {

    @Resource
    private SseService sseService;

    @Resource
    NowUserGetter nowUserGetter;

    /**
     * 创建SSE连接
     */
    @PostMapping(path = "/connect")
    public SseEmitter sse() {
        Long userId = nowUserGetter.getNowUser().getAccountId();
        return sseService.connect(userId);
    }
    /*
     *//**
     * 关闭SSE连接
     *
     * @param uuid 客户端ID
     **//*
    @GetMapping("/disconnect")
    public void disconnect(@RequestParam String uuid) {
        sseService.closeSseConnect(uuid);
    }*/

}

